package com.ruoyi.yljf.controller.AppController;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.BaseQuery;
import com.ruoyi.common.core.domain.BaseQueryPage;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.security.annotation.Anonymous;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.yljf.domain.Goods;
import com.ruoyi.yljf.domain.User;
import com.ruoyi.yljf.domain.dto.*;
import com.ruoyi.yljf.domain.enums.yljfEnums;
import com.ruoyi.yljf.domain.vo.GoodsVO;
import com.ruoyi.yljf.domain.vo.UserInfoVO;
import com.ruoyi.yljf.domain.vo.UserScoreRecordVO;
import com.ruoyi.yljf.domain.vo.UserVO;
import com.ruoyi.yljf.service.IGoodsService;
import com.ruoyi.yljf.service.IUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

/**
 * 用户个人信息接口
 *
 */
@RequestMapping("/api/userInfo")
@RestController
public class ApiUserInfoController extends BaseController {

    @Resource
    private IUserService userService;


    /**
     * 个人资料
     */
    @GetMapping()
    public AjaxResult userInfo() {
        User userById = userService.getUserById(SecurityUtils.getUserId());
        UserInfoVO userInfoVO= BeanUtil.copyProperties(userById, UserInfoVO.class);
        return success(userInfoVO);
    }

    /**
     * 修改个人资料
     */
    @PostMapping("/updateUserInfo")
    public AjaxResult updateUserInfo(@RequestBody UserInfoDTO userInfoDTO) {
        return success(userService.updateUserInfo(userInfoDTO));
    }

    /**
     * 用户余额兑换
     * @param dto：兑换类型 和 兑换数量
     *           1：祈福币  2：祈智币
     * @param req：需要获取当前用户信息
     * @return
     */
    @PostMapping("/convert")
    public AjaxResult convert(ConvertDTO dto, HttpServletRequest req) {
        return userService.convert(dto, req);
    }
}
